<template>
    <div>
        <el-page-header icon="" content="首页" title=" "></el-page-header>

        <el-card shadow="hover">
            <el-row>
                <el-col :span="4"><el-avatar :src="avatarUrl" :size="80"/></el-col>
                <el-col :span="20" style="line-height: 80px;">Welcome {{store.state.userInfo.username}} &nbsp;&nbsp;{{ welcomeText }}</el-col>
            </el-row>
        </el-card>
        <el-card shadow="hover">
            <template #header>
                <div class="card-header">
                    <span>产品</span>
                </div>
            </template>

            <el-carousel :interval="4000" type="card" height="200px">
                <el-carousel-item v-for="item in loopList" :key="item._id">
                    <div :style='{backgroundImage:`url(http://localhost:3000${item.cover})`,backgroundSize:"cover"}'>
                        <h3 justify="center">{{ item.title }}</h3>
                    </div>
                </el-carousel-item>
            </el-carousel>
        </el-card>
    </div>
</template>

<script setup>
import { useStore } from 'vuex';
import {computed,onMounted,ref} from 'vue'
import axios from 'axios';

const avatarUrl = computed(()=>store.state.userInfo.avatar ? 'http://localhost:3000' + store.state.userInfo.avatar : 'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png')

const welcomeText = computed(()=>new Date().getHours() < 14 ? "元气满满的一天" : "今天也别忘了下午茶" )
const store = useStore()
const loopList = ref([])

onMounted(async ()=>{
    const result = await axios.get(`/adminapi/product/list`)
    loopList.value = result.data.data   

})
</script>

<style lang="scss" scoped>
.el-card {
    margin-top: 50px;
}
.el-carousel__item h3 {
  color: white;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>